package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/09/02 23:12
 **/
public class Day48_8_Offer42_MaxSubArray {
    class Solution {
        public int maxSubArray(int[] nums) {
            if(nums.length == 1) return nums[0];
            int max = nums[0];
            for(int i = 1; i < nums.length; ++i){
                nums[i] = Math.max(nums[i-1]+nums[i], nums[i]);
                if(nums[i] > max) max = nums[i];
            }
            return max;
        }
    }
}